    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecommerce.dao;

import ecommerce.model.Customer;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Hadi
 */
@Repository
public class CustomerDao {
    @Autowired private SessionFactory sessionFactory;

    public void save(Customer c){
        sessionFactory.getCurrentSession().saveOrUpdate(c);
    }

    public void delete(Customer c){
        sessionFactory.getCurrentSession().delete(c);
    }

    public Customer findById(Long id){
        return (Customer) sessionFactory.getCurrentSession().get(Customer.class, id);
    }

    public List<Customer> getAll(){
        return sessionFactory.getCurrentSession().createQuery("from Customer").list();
    }
}
